package com.briup.oagg.facade.web.controller.model;

import com.briup.oagg.facade.web.vm.page.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.facade.service.model.IModelInfoService;
import com.briup.oagg.facade.web.vm.model.ModelInfoVM;
import com.briup.oagg.facade.web.vm.model.ModelInfoAddOrUpdateVM;
import com.briup.oagg.facade.web.vm.model.ModelInfoListVM;
import com.briup.oagg.facade.web.vm.model.ModelStatisticVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模型信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "2.1.模型信息管理服务")
@RestController
@RequestMapping("/model")
public class ModelInfoController {
    @Autowired
    private IModelInfoService service;

    @ApiOperation(value = "分页多条件查询模型及对应的数据集和地质信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true,defaultValue = "1",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true,defaultValue = "5",dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "modelName",value = "模型名称"),
            @ApiImplicitParam(name = "modelType",value = "模型类型(classification(分类),cluster(聚类),regression(回归))",allowableValues = "classification,cluster,regression",dataTypeClass = String.class)
    })
    @GetMapping("/page")
    public Response<Page<ModelInfoListVM>> findByPage(@RequestParam Integer pageNum,
                                                      @RequestParam Integer pageSize,
                                                      String modelType, String modelName){
        Page<ModelInfoListVM> page = service.findByPage(pageNum, pageSize, modelName,modelType);
        return Response.success(page);
    }

    @ApiOperation(value = "新增或修改模型信息",notes = "新增时，不提供参数modelId,修改模型时，根据modelId，修改模型名称")
    @PostMapping
    public Response<String> addOrUpdate(@RequestBody ModelInfoAddOrUpdateVM vm){
        service.addOrUpdate(vm);
        return Response.success();
    }


    @ApiOperation(value = "根据模型编号删除模型信息")
    @DeleteMapping("/{modelId}")
    public Response deleteById(@PathVariable String modelId){
        service.deleteById(modelId);
        return Response.success();
    }

    @ApiOperation("统计模型数量")
    @GetMapping("/count")
    public Response<Integer> count(){
        int num = service.count();
        return Response.success(num);
    }

    @ApiOperation(value = "按月统计各分类模型数量",notes = "默认返回当前年内各月份各类型模型数据统计")
    @ApiImplicitParam(name = "year",value = "指定年份",dataTypeClass = Integer.class)
    @GetMapping("/modelCount/month")
    public Response<List<ModelStatisticVM>> countByMonth(Integer year){
        List<ModelStatisticVM> list = service.countByMonth(year);
        return Response.success(list);
    }

    @ApiOperation(value = "按月统计各类模型训练数量",notes = "默认返回当前年内各月份各类型模型数据统计")
    @ApiImplicitParam(name = "year",value = "指定年份",dataTypeClass = Integer.class)
    @GetMapping("/trainCount/month")
    public Response countModelTrainByMonth(Integer year){
        List<ModelStatisticVM> list = service.countModelTrainByMonth(year);
        return Response.success(list);
    }
    @ApiOperation("根据模型类型查询所有的模型信息")
    @ApiImplicitParam(name = "modelType",value = "模型类型(classification(分类),cluster(聚类),regression(回归))",allowableValues = "classification,cluster,regression",dataTypeClass = String.class)
    @GetMapping("/type")
    public Response<List<ModelInfoVM>> findByType(@RequestParam String modelType){
        List<ModelInfoVM> list = service.findByType(modelType);
        return Response.success(list);
    }
}
